package com.godofgamblers.hotelmanagementsystem.mapper;

import com.godofgamblers.hotelmanagementsystem.dto.TimeDto;
import com.godofgamblers.hotelmanagementsystem.pojo.Check_In_Info;
import com.godofgamblers.hotelmanagementsystem.pojo.Room;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

/**
 * 入住信息表相关数据库操作
 */
@Repository
public interface Check_In_InfoMapper {

    /**
     * 插入入住信息
     * @param check_in_infoPojo
     * @return int 影响行数
     */
    @Insert("insert into check_in_info(room_num,actual_name,id_card,check_in_time,check_out_time,order_item_id) values(#{room_num},#{actual_name},#{id_card},#{check_in_time},#{check_out_time},#{order_item_id})")
    public int addCheckInInfo(Check_In_Info check_in_infoPojo);


    /**
     * 修改退房时间
     * @param check_in_info  传入房间编号、退房时间
     * @return 影响行数
     */
    @Update("UPDATE check_in_info SET check_out_time=#{check_out_time} WHERE check_out_time IS NULL AND room_num=#{room_num}")
    public int updateCheckOutTime(Check_In_Info check_in_info);

    /**
     * 查询退房的订单项id
     * @return Integer 订单项id
     */
    @Select("select order_item_id from check_in_info where check_out_time IS NULL AND room_num=#{room_num}")
    public Integer checkOutFindOrderItem(Check_In_Info check_in_info);

    /**
     * 查询实际入住人姓名
     * @param order_item_id
     * @return
     */
    @Select("select actual_name from check_in_info where order_item_id = #{order_item_id} and flag=1")
    String findActualNameByOrderItemId(Integer order_item_id);

    //根据订单项id找到实际入住时间和实际离开时间
    @Select("SELECT check_in_time,check_out_time FROM check_in_info WHERE order_item_id = #{order_item_id}")
    public TimeDto findTime(Integer order_item_id);
}
